const { service } = require("../request");
//哈希值
const crypto = require("crypto");
const { log } = require("console");

//海事预警登录
function login(data) {
  return service({
    url: "https://www.hehaijianghu.com/api/pub/checkLogin",
    method: "post",
    data,
  });
}

//海事科技预警 番禺大桥范围ais
function getSnData(data) {
  return service({
    url: "https://www.hehaijianghu.com/api/Ship/getSnData",
    method: "post",
    data,
  });
}

//上传番禺大桥系统
function uploadShipData(data, rnd) {
  let hax = generateSignature(data,rnd);
  // console.log(26, hax);
  return service({
    // url: "https://bmsapi.gdjkjc.cn:13578/Ship/AddNearbyShip",
    url: "https://bmsapi.gdjkjc.cn:13579/Ship/AddNearbyShip",
    method: "post",
    headers: { 'appKey': "677f25bf2118479e", 'rnd': rnd, 'sign': hax },
    data,
  });
}

// 生成签名哈希
function generateSignature(postBody, rnd) {
  const rawString =
    JSON.stringify(postBody) +
    rnd +
    "677f25bf2118479e" +
    "d31c6f12c6574f4c91f8e533ceb744f7";
  return crypto
    .createHash("sha1")
    .update(rawString,"utf-8")
    .digest("hex")
    .toUpperCase();
}
module.exports = { login, getSnData, uploadShipData };
